/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.pa165.portalnahouby.implementation.serviceimplementation;

import cz.muni.fi.pa165.portalnahouby.api.dto.ForestDTO;
import cz.muni.fi.pa165.portalnahouby.api.serviceinterface.ForestService;
import cz.muni.fi.pa165.portalnahouby.implementation.daointerface.ForestDAO;
import cz.muni.fi.pa165.portalnahouby.implementation.entity.Forest;
import cz.muni.fi.pa165.portalnahouby.implementation.util.EntityDTOConvertor;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Implementation of forest service
 *
 * @author Tomáš Čejka
 */
@Service
public class ForestServiceImpl implements ForestService {

    @Autowired
    private ForestDAO forestDAO;

    public void setForestDAO(ForestDAO forestDAO) {
        this.forestDAO = forestDAO;
    }

    @Override
    public void addForest(ForestDTO forest) {
        Forest forestEntity = EntityDTOConvertor.convertForest(forest);
        forestDAO.addForest(forestEntity);
        forest.setId(forestEntity.getId());
    }

    @Override
    public void editForest(ForestDTO forest) {
        forestDAO.editForest(EntityDTOConvertor.convertForest(forest));
    }

    @Override
    public void deleteForest(Long id) {
        forestDAO.deleteForest(id);
    }

    @Override
    public ForestDTO findForest(Long id) {
        return EntityDTOConvertor.convertForest(forestDAO.findForest(id));
    }

    @Override
    public List<ForestDTO> getAllForests() {
        List<Forest> entityList = forestDAO.getAllForests();
        List<ForestDTO> dtoList = new ArrayList<ForestDTO>();
        for (Forest forest : entityList) {
            dtoList.add(EntityDTOConvertor.convertForest(forest));
        }
        
        return dtoList;
    }
}
